

function immNeg=negative(image)
%create output image of the same size as the input image
[rows,cols]=size(image);
immNeg=zeros(rows,cols);

%conversion for working double
%values range in [0,1] , instead of [0,255]
image=im2double(image);

%finding max and min gray level value
max_gray=max(max(image));

%We must do the mapping keeping in mind to consider also graylevels not
%used in the image
%In this way we are sure to have a completely reversed histogram
%trasformation
for i=1:rows
    for j=1:cols
        immNeg(i,j)=max_gray - image(i,j)  + (1.0-max_gray);
    end
end

%conversion back to uint8
immNeg=im2uint8(immNeg);
